package com.gtw.modules.sys.controller;

import com.gtw.common.utils.PageUtils;
import com.gtw.common.utils.Query;
import com.gtw.common.utils.R;
import com.gtw.modules.entity.TbProxyuserPay;
import com.gtw.modules.sys.service.TbProxyuserPayService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/** 代理用户打款凭证
 * Created by wuye on 2018/3/20.
 */
@RestController
@RequestMapping("/sys/proxyuserpay")
public class SysTbProxyuserPayController {

    @Autowired
    private TbProxyuserPayService proxyuserPayService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:proxyuserpay:list")
    public R list(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);

        List<TbProxyuserPay> proxyuserPayList = proxyuserPayService.queryList(query);
        int total = proxyuserPayService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(proxyuserPayList, total, query.getLimit(), query.getPage());

        return R.ok().put("data", pageUtil);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:proxyuserpay:info")
    public R info(@PathVariable("id") Integer id){
        TbProxyuserPay proxyuserPay = proxyuserPayService.queryObject(id);

        return R.ok().put("data", proxyuserPay);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:proxyuserpay:save")
    public R save(@RequestBody TbProxyuserPay proxyuserPay){
        proxyuserPayService.save(proxyuserPay);

        return R.ok();
    }

    /**
     * 修改(审核)
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:proxyuserpay:update")
    public R update(@RequestBody TbProxyuserPay proxyuserPay){
        proxyuserPay.setStatus(1);
        proxyuserPayService.update(proxyuserPay);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:proxyuserpay:delete")
    public R delete(@RequestBody Integer[] ids){
        proxyuserPayService.deleteBatch(ids);

        return R.ok();
    }
}
